package com.dyz.leetcode._12_linkedList;

import com.dyz.leetcode.ListNode;

public class _24_splitListToParts {
    public ListNode swapPairs(ListNode head) {
        if(head==null||head.next==null){return head;}
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode prev = dummy;
        ListNode first = head;
        ListNode second = head.next;
        while (second!=null){
            ListNode next = second.next;
            prev.next = second;
            second.next = first;
            first.next = next;


            prev=first;
            first = next;
            if(first==null){
                break;
            }
            second = first.next;//
        }
       return dummy.next;
    }
}
